layui.config({
    base: "js/"
}).use(['form', 'layer', 'jquery', 'layedit', 'laydate'], function () {
    var form = layui.form(),
        layer = parent.layer === undefined ? layui.layer : parent.layer,
        laypage = layui.laypage,
        layedit = layui.layedit,
        laydate = layui.laydate,
        $ = layui.jquery;
    var d1 = sessionStorage.getItem("userInfo");
    var f = JSON.parse(d1)
     console.log(f)
	$(".newsAuthor").val(f.name); //昵称
    //创建一个编辑器
    /* 	var editIndex = layedit.build('news_content');*/
    var addNewsArray = [], addNews;
    form.on("submit(addNews)", function (data) {
        console.log(data.content);


        //是否添加过信息
        if (window.sessionStorage.getItem("addNews")) {
            addNewsArray = JSON.parse(window.sessionStorage.getItem("addNews"));
        }
        /*	//显示、审核状态
            var isShow = data.field.show=="on" ? "checked" : "",
                newsStatus = data.field.shenhe=="on" ? "已审核" : "未审核";*/

        addNews = '{"newsName":"' + $(".newsName").val() + '",';  //文章名称
        /*addNews += '"newsId":"'+new Date().getTime()+'",';	 //文章id*/
        /* 		addNews += '"newsLook":"'+$(".newsLook option").eq($(".newsLook").val()).text()+'",'; //开放浏览*/
        addNews += '"newsTime":"' + $(".newsTime").val() + '",'; //发布时间
        addNews += '"newsAuthor":"' + $(".newsAuthor").val() + '",'; //文章作者
        addNews += '"newsAuthor":"' + $("#news_content").val() + '",'; //文章内容
        /* 		addNews += '"isShow":"'+ isShow +'",';  //是否展示
                 addNews += '"newsStatus":"'+ newsStatus +'"}'; //审核状态*/
        var tittle = $(".newsName").val();
        var author = $(".newsAuthor").val(f.name); //昵称;
        var time = $(".newsTime").val();
        var content = $("#news_content").val();
        // var content=	document.getElementsByName("newscontent");
        /*
                alert(content)
        */

        console.log(tittle, author, time, content)
        $.ajax({
            url: "http://localhost:8080/com.3group.personality/notice/insert?author" + author + "&tittle" + tittle + "&time" + time + "&content" + content,
            type: "post",
            dataType: "json",
            success: function () {
                alert("发布成功")
            }

        })


        addNewsArray.unshift(JSON.parse(addNews));
        window.sessionStorage.setItem("addNews", JSON.stringify(addNewsArray));
        //弹出loading
        var index = top.layer.msg('数据提交中，请稍候', {icon: 16, time: false, shade: 0.8});
        setTimeout(function () {
            top.layer.close(index);
            top.layer.msg("公告发布成功！");
            layer.closeAll("iframe");
            //刷新父页面
            parent.location.reload();
        }, 2000);
        return false;
    })

})
